BEGIN TRAN



ROLLBACK  
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_observaciones_por_id_turno]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sp_observaciones_por_id_turno]
GO

  create procedure sp_observaciones_por_id_turno
      @id_turno bigint
    as
          SELECT  
                    id as observacion_id
                    ,id_sucursal as observacion_id_sucursal
                    ,cod_sucursal as observacion_cod_sucursal
                    ,id_turno as observacion_id_turno
                    ,id_supervisor as observacion_id_supervisor
                    ,observacion as observacion_observacion
                    ,create_date as observacion_create_date
                    ,sup.User_intUserNo  as supervisor_User_intUserNo
                    ,sup.User_strFirstName as supervisor_User_strFirstName
                    ,sup.User_strLastName as supervisor_User_strLastName
                    ,sup.User_strEnabled as supervisor_User_strEnabled
                    ,sup.User_strHOPayrollCode as supervisor_User_strHOPayrollCode
                    ,sup.User_intPIN as supervisor_User_intPIN
                    ,sup.UserG_strCode as supervisor_UserG_strCode
                    FROM  observaciones,Usuarios as sup
                    WHERE  observaciones.id_supervisor= sup.User_intUserNo 
                    and observaciones.id_turno = @id_turno
  GO

  
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_observaciones_c]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sp_observaciones_c]
GO

CREATE PROCEDURE sp_observaciones_c
                    @id_sucursal varchar(10)
                   ,@cod_sucursal varchar(10)
                   ,@id_turno bigint
                   ,@id_supervisor bigint
                   ,@observacion varchar(800)
                   ,@id bigint OUTPUT
as
        INSERT INTO [dbo].[observaciones]
                   ([id_sucursal]
                   ,[cod_sucursal]
                   ,[id_turno]
                   ,[id_supervisor]
                   ,[observacion])
             VALUES
                   (@id_sucursal
                   ,@cod_sucursal
                   ,@id_turno
                   ,@id_supervisor
                   ,@observacion)
        
        select @id = SCOPE_IDENTITY()
        select @id
GO